/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import DB.Database;
import beans.*;
import com.mysql.jdbc.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author DE SILVA
 */
public class DataAcessObject {

    /**
     *
     * @return
     * @throws SQLException
     */
    public static Pays detailsPays(String Pays) throws SQLException {

        Pays pays=null;
        try {
            Database.getConnection();
            String query = Requetes.listePays;
            PreparedStatement pstmt = (PreparedStatement) Database.getConnection().prepareStatement(query);
            pstmt.setString(1, Pays);
            ResultSet rs = pstmt.executeQuery();
            if(rs.next()) {
                pays = new Pays();
                pays.setIdPays(rs.getString(1));
                pays.setNom_Pays(rs.getString(2));
                pays.setCapitale(rs.getString(3));
                pays.setHabitants(rs.getString(4));
                pays.setDecalageHoraire(rs.getString(5));
                pays.setLangue(rs.getString(6));
                pays.setMonnaie(rs.getString(7));
                pays.setIndicatif(rs.getString(8));
            }


        } finally {
            Database.getConnection().close();
        }
        return pays;

    }
    public static List<Pays> listePays() throws SQLException {

        ArrayList<Pays> listePaysParZone =new ArrayList<Pays>();
        Pays pays=null;
        try {
            Database.getConnection();
            String query = Requetes.lesPays;
            Statement st = (Statement) Database.getConnection().createStatement();
           ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                pays = new Pays();
                pays.setIdPays(rs.getString(1));
                pays.setNom_Pays(rs.getString(2));
                listePaysParZone.add(pays);
            }


        } finally {
            Database.getConnection().close();
        }
        return listePaysParZone;

    }
/**
 *
 * @param ID_Pays
 * @return listeMaladieParZone
 * @throws SQLException
 */
     public static ArrayList<Maladie> listeMaladiesEnFonctionPays(String ID_Pays ) throws SQLException {

        ArrayList<Maladie> listeMaladieParZone = new ArrayList<Maladie>();
        Maladie maladie=null;
        try {
            Database.getConnection();
            String query = Requetes.listeMaladiesApartirPays;
            PreparedStatement pstmt = (PreparedStatement) Database.getConnection().prepareStatement(query);
            pstmt.setString(1, ID_Pays);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                maladie = new Maladie();
                maladie.setNom_maladie(rs.getString(1));
                listeMaladieParZone.add(maladie);
            }
        } finally {
            Database.getConnection().close();
        }
        return listeMaladieParZone;

    }
/**
 *
 * @param ID_Pays
 * @return listeVaccinParZone
 * @throws SQLException
 */
   public static ArrayList<Vaccination> listeVaccinEnFonctionPays(String ID_Pays ) throws SQLException {
        ArrayList<Vaccination> listeVaccinParZone = new ArrayList<Vaccination>();
        Vaccination vaccin=null;
        try {
            Database.getConnection();
            String query = Requetes.listeVaccinAPartirPays;
            PreparedStatement pstmt = (PreparedStatement) Database.getConnection().prepareStatement(query);
            pstmt.setString(1, ID_Pays);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                vaccin = new Vaccination();
                vaccin.setMaladie(rs.getString(1));
                vaccin.setType(rs.getByte(2));
                listeVaccinParZone.add(vaccin);
            }

        } finally {
            Database.getConnection().close();
        }
        return listeVaccinParZone;

    }

}
